package com.bicon.botu.medical.service.impl

import com.baomidou.mybatisplus.mapper.EntityWrapper
import com.baomidou.mybatisplus.service.impl.ServiceImpl
import com.bicon.botu.core.base.common.BusinessException
import com.bicon.botu.core.base.common.utils.DateUtil
import com.bicon.botu.medical.common.constant.Constant
import com.bicon.botu.medical.dao.mapper.HealthInfoMapper
import com.bicon.botu.medical.model.entity.HealthInfo
import com.bicon.botu.medical.service.IHealthInfoService
import commonx.core.date.calculateAge
import org.springframework.stereotype.Service

/**
 * 体征数据业务接口 -- 实现类
 *
 * @author 刘小鹏
 * @date 2018/07/17
 */
@Service
open class HealthInfoServiceImpl : ServiceImpl<HealthInfoMapper, HealthInfo>(), IHealthInfoService {


    override fun getHealthInformationCategoryByAgeRange(birthday: String): List<HealthInfo> {
        val age = 30
        if (!DateUtil.isDate(birthday)) {
            throw BusinessException("传入的出生日期不是日期字符串")
        }
        val calculateAge = DateUtil.StringToDate(birthday).calculateAge()
        val wrapper = EntityWrapper<HealthInfo>()
        if (calculateAge >= age) {
            wrapper.where("info_type={0}", Constant.AGE_30_ABOVE)
        } else if (calculateAge < age) {
            wrapper.where("info_type={0}", Constant.AGE_30_UNDER)
        }
        return this.selectList(wrapper)
    }
}